home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 183_01 / dirgt.asm < prev    next >
Assembly Source File  |  1985-10-27  |  14KB  |  325 lines

  1. page ,132
  2. title **** DIRGT.ASM ***
  3. comment *
  4.  
  5. =========================================================================
  6. DIRGT.ASM
  7. 03-06-85  by  Thomas E. Link
  8.  
  9.      Procedure to be called from IBM PASCAL V2.0 or function in LATTICE C
  10. to get disk directory including VOLUME NAME, file LENGTH,DATE, and TIME.
  11.  
  12. To use in PASCAL first:
  13.         type  dirrect = record
  14.                 fname:string(12);
  15.                 ftime:word;
  16.                 fdate:word;
  17.                 flen:array[0..1] of word;
  18.                 end;
  19.               lookst = string(40);
  20.               volst = string(13);
  21.               countt = word;
  22.         var   dir_rec : array[0..111] of dirrect;
  23.  
  24.        looks := 'drive id:\path\filename.ext'+CHR(0)
  25.            ' name to search for, same as with DIR command
  26.            ' path works only when used with DOS 2.x
  27.            ' This string must terminate with a CHR$(0) !
  28.  
  29.    procedure DIRGET(var looks lookst; var dir_rec[0]:dirrect;
  30.                     var vols:volst; var count:countt);extern;
  31.         If Assembling for PASCAL leave the equate (pascal equ 1) below.
  32.         If using LATTICE C delete that line.
  33. =========================================================================
  34. *
  35. pascal equ 1
  36. page
  37. workstruc       struc
  38.         dircount        dw      (?)
  39.         dos_version     db      (?)
  40.         filler          db      (?)
  41.         saved_sp        dw      (?)
  42.         fcb             db      48 dup (?)
  43.         dta             db      48 dup (?)
  44. workstruc       ends
  45.  
  46. ifdef   pascal  ;-------------------------------------------------------
  47. stack   struc                        ; Define the stack area for PASCAL
  48.         workarea        db      type workstruc dup (?)
  49.         pushed_bp       dw      (?)
  50.         return          dw      (?)
  51.         address         dw      (?)
  52.         countnumad      dw      (?)
  53.         volstrgad       dw      (?)
  54.         dirrecarad      dw      (?)
  55.         lookstringad    dw      (?)
  56. stack   ends
  57.         poplen  equ     lookstringad - address
  58.  
  59. else    ;----------------- 
  60.  
  61. stack   struc                      ; Define the stack area for C.
  62.         workarea        db      type workstruc dup (?)
  63.         pushed_bp       dw      (?)
  64.         address         dw      (?)
  65.         countnumad      dw      (?)
  66.         volstrgad       dw      (?)
  67.         dirrecarad      dw      (?)
  68.         lookstringad    dw      (?)
  69. stack   ends
  70.         poplen  equ     0
  71.  
  72. endif   ;---------------------------------------------------------------
  73.  
  74. data    segment public  'DATA'
  75. data    ends
  76. dgroup  group   data
  77.  
  78. ifdef   pascal ;---------- Pascal --------------------------------------
  79. prog    segment public 'CODE'
  80.         assume CS:prog, DS:nothing, ES:nothing
  81.         public  DIRGET
  82. DIRGET  proc    far
  83.  
  84. else    ;----------------- C definitions
  85. pgroup  group   prog
  86.         assume  CS:pgroup, DS:nothing, ES:nothing
  87. prog    segment public  'PROG'
  88.         public  DIRGET,_DIRGET,DIRGET_
  89. DIRGET  proc    near
  90.  
  91. endif   ;----------------------------------------------------------------
  92.  
  93. page
  94. DIRGET_:
  95. _DIRGET:
  96.         cld                          ; Clear direction flag.
  97.         push    bp
  98.         mov     bp,sp                ; Point to arguments on stack.
  99.         sub     bp,type workstruc    ; Give us room to work
  100.         mov     [bp].saved_sp,sp     ; Save the stack pointer
  101.         mov     sp,bp                ; and move it below workarea.
  102.         mov     [bp].dircount,0      ; Move zero to directory count.
  103.  
  104. ;----------------- determine DOS version, store in variable
  105.         mov     ah,48                ; find DOS version number
  106.         int     21h
  107.         mov     [bp].dos_version,al  ; and store in variable
  108.  
  109. ;-----------------  parse filename
  110.         mov     ax,ss
  111.         mov     es,ax           ; Have ES point at STACK **************
  112.         mov     di,bp           ; and DI point 
  113.         add     di,offset fcb   ;            to FCB area.
  114.         mov     si,[bp].lookstringad    ; Point SI at file specifier
  115.         mov     ah,29H          ; DOS function to parse filename
  116.         mov     al,1            ; scan off leading separators
  117.         int     21H             ; DOS function call
  118.         push    ds              ; Get DATA seg into ES.***************
  119.         pop     es
  120.         cmp     al,0FFH         ; Any errors on parsing ?
  121.         jne     dir2            ; No - continue
  122.         jmp     done            ; YES - end.
  123.  
  124. ;----------------- get addresses of the parms
  125. dir2:
  126.         mov     dx,bp           ; Put address of workspace into DX
  127.         add     dx,offset dta   ; Bump to DTA
  128.         push    ds              ; Save value of DS
  129.         mov     ax,ss           ; and move STACK into DS.**************
  130.         mov     ds,ax
  131.         mov     ah,1AH          ; Set AH for *SET DTA* function call.
  132.         int     21H             ; Use DOS interrupt.
  133.  
  134.         cmp     [bp].dos_version,2 ; if DOS 2.0 or greater
  135.         jae     dos2_search        ; use special routine
  136.  
  137. ;----------------- DOS 1.0, 1.1 search
  138.         mov     dx,bp           ; Point DX at workspace
  139.         add     dx,offset fcb   ;       bump to FCB area.
  140.         mov     ah,11H          ; Set AH for directory search.
  141.         int     21H             ; Use DOS interrupt.
  142.         cmp     al,0FFH         ; Any matches found ?
  143.         je      done1           ; No - so end
  144.         inc     [bp].dircount   ; Yes - count first entry.
  145.         call    move            ; Go move entry into fnames().
  146. dirloop:
  147.         mov     ah,12H          ; Set AH for continuation of search.
  148.         int     21H             ; Use DOS interrupt.
  149.         cmp     al,0FFH         ; Any matches found ?
  150.         je      done1           ; No - jump to exit
  151.         inc     [bp].dircount   ; Yes - count this entry.
  152.         call    move            ; Go move entry into arrays.
  153.         jmp     dirloop         ; Do again.
  154.  
  155. ;----------------- DOS 2.x  search
  156. dos2_search:
  157.         mov     dx,[bp].lookstringad    ; Point DX at file specifier
  158.         mov     ah,4EH          ; Set AH for directory search.
  159.         mov     cx,10H          ; search for files and directories.
  160.         int     21H             ; Use DOS interrupt.
  161.         jc      findlabel       ; No matches - so look for a label
  162.         inc     [bp].dircount   ; found - count first entry.
  163.         call    move2           ; Go move entry into arrays.
  164. dir2loop:
  165.         mov     cx,10H
  166.         mov     ah,4FH          ; Set AH for continuation of search.
  167.         int     21H             ; Use DOS interrupt.
  168.         jc      findlabel       ; No matches - so look for a label
  169.         inc     [bp].dircount   ; match - count this entry.
  170.         call    move2           ; Go move entry into arrays.
  171.         jmp     dir2loop        ; Do again.
  172. findlabel:
  173.         call    get_label       ; look for a volume label
  174. done1:
  175.         pop     ds              ; restore DS to DATA  ****************
  176. done:
  177.         mov     ax,[bp].dircount      ; Move entries count to AX.
  178.         mov     di,[bp].countnumad    ; Get address of COUNT%
  179.         mov     [di],ax         ; Put entry count in COUNT%.
  180.         mov     sp,[bp].saved_sp      ; Restore SP.
  181.         pop     bp              ; Restore BP.
  182.         ret     poplen          ; Return and throw away parms if PASCAL
  183.  
  184. ;........................................................................
  185. ;----------------- procedure to store results from DOS 1.x search
  186. move    proc    near
  187. ;----------------- first move filename into string array
  188.         mov     di,[bp].dirrecarad   ; Move name address to DI and BX.
  189.         mov     bx,di
  190.         add     bx,20           ; Have BX point at next record
  191.         mov     [bp].dirrecarad,bx   ; and save in variable
  192.         mov     si,bp
  193.         add     si,offset dta+1 ; put file name(in DTA) address into SI
  194.         mov     cx,4            ; Length of name in words
  195.         rep     movsw           ; Move name into array.
  196.         mov     byte ptr [di],'.' ; Put period in filename.
  197.         inc     di              ; Bump DI past '.'
  198.         mov     cx,3